@extends("admin.layouts.main")
<style>
    .my-ver-align {
        vertical-align: -2px;
    }

    .btn-link {
        color: gray;
    }

    .my-daili {
        position: relative;
    }
</style>
@section("content")
<div class="container-fiuld p-3">
    <div class="card">
        <div class="card-body pt-1">
            <div class="row mt-1 mb-2">
                <div class="col-lg-12 pt-3 pb-3" style="background-color:#F2F2F2">
                    <form class="form-inline position-relative flex-nowrap justify-content-between">
                        <div class="d-flex align-items-center flex-wrap">
                            <select class="form-control" name="search">
                                <option value="">请选择</option>
                                <option value="title" @if($search=='title') selected @endif>标题</option>
                            </select>
                            <input type="text" id="keyword" name="keyword" placeholder="请输入搜索内容" value="{{ $keyword }}"
                                   class="ml-4 mr-5 form-control">
                            <a class="btn btn-primary btn-sm ml-5 mr-3 search text-white">查询</a>
                            <button type="reset" class="btn btn-secondary mr-3 btn-sm">重置</button>
                        </div>
						@if(in_array('announ.create', $menuRule))
                        <a class="btn btn-success btn-sm my-daili" href="{{ route('announ.create') }}">添加公告</a>
						@endif
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12 table-responsive">
                    <table class="table layui-form h6">
                        <thead class="thead-light">
                        <tr class="text-dark">
                            <th>ID</th>
                            <th>标题</th>
                            <th>内容</th>
                            <th>添加时间</th>
                            <th>更新时间</th>
							@if(in_array('announ.edit', $menuRule) || in_array('announ.delete', $menuRule))
                            <th>操作</th>
							@endif
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($announ as $v)
                        <tr>
                            <td>{{ $v->id }}</td>
                            <td>{{ $v->title}}</td>
                            <td class="w-50">{!! $v->content !!}</td>
                            <td>{{ $v->created_at}}</td>
                            <td>{{ $v->updated_at}}</td>
							@if(in_array('announ.edit', $menuRule) || in_array('announ.delete', $menuRule))
                            <td>
								@if(in_array('announ.edit', $menuRule))
                                <a href="{{ route('announ.edit', ['id' => $v->id]) }}" class="btn btn-primary btn-sm edit">修改</a>
								@endif
								
								@if(in_array('announ.delete', $menuRule))
								<a data-url="{{ route('announ.delete', ['id' => $v->id]) }}" data-type="DELETE" class="btn text-white btn-danger btn-sm del">删除</a>
								@endif
                            </td>
							@endif
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div style="text-align: right;">
            {{ $announ->appends(['search'=>$search, 'keyword' => $keyword])->links('admin.layouts.paginate') }}
        </div>
    </div>
</div>
@endsection

@section("js")
<script type="text/javascript">
    layui.use(['form', 'ori'], function () {
        var form = layui.form,
            ori = layui.ori,
            dialog = layui.dialog,
            $ = layui.$
        $('[type=reset]').click(function (e) {
            e.preventDefault();
            $('[name=search]').val("");
            $('[name=keyword]').val("");
        });
		$('.del').click(function () {
                var _that = $(this);
                dialog.confirm('确认删除', function () {
                    ori.submit(_that, '', function () {
                        _that.closest('tr').remove();
                    });
                });
            });
        $('.search').click(function () {
            var search = $('[name="search"]').val();
            var keyword = $("#keyword").val();
            location.href = "{{ route('announ.index') }}" + '?search=' + search + ' &keyword=' + keyword;
        });
    });
</script>
@endsection
